package com.amkai.aes.webservice.binary.objecthandler.scheduler;

import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.amkai.aes.aescommon.service.binary.job.schedule.CaseCommitJob;
import com.amkai.aes.generatedbeans.pmcase.PmCase;
import com.amkai.aes.webservice.binary.JobObjectHandler;
import com.amkai.common.extensions.hibernate.config.SiteManager;
import com.amkai.common.extensions.hibernate.config.manager.SessionManager;

public class CaseCommitHandler implements JobObjectHandler<CaseCommitJob, Serializable, Boolean> {

	private static final Log logger = LogFactory.getLog(CaseCommitHandler.class);
	
	@Override
	public Boolean process(CaseCommitJob job, Serializable object)
			throws Exception {
		Boolean result = Boolean.TRUE;
		if(( object != null) && ( object instanceof PmCase )) {
			PmCase c = (PmCase)object;
			SessionManager sm = SiteManager.Start();
			try {
				sm.openSession();
				sm.openTransaction();
				sm.saveRAD(c);
				sm.commitTransaction();
			} catch( Exception ex ) {
				result = Boolean.FALSE;
				ex.printStackTrace();
				logger.error("", ex);
			} finally {
				sm.closeSession();
			}
		}
		return result;
	}


}
